package com.hardydou.system.controller;

import com.github.pagehelper.PageInfo;
import com.hardydou.common.result.Result;
import com.hardydou.common.controller.BaseController;
import com.hardydou.common.result.ResultHelper;
import com.hardydou.system.model.SystemOperLog;
import com.hardydou.system.service.ISystemOperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * @author ：hardy
 * @description：
 * @date ：Created in 2020-03-10
 * @Copyright ：Hardydou.com
 */
@Controller
@RequestMapping("/system/operlog")
@Api(tags = "操作日志")
public class SysOperLogController extends BaseController {
    public final static String model = "sys";
    public final static String subModel = "operlog";

    @Autowired
    ISystemOperLogService operLogService;

    @ApiIgnore
    @GetMapping("")
    public String index() {
        return page("list");
    }

    @ApiIgnore
    @GetMapping("/info")
    public String info(long operId, Model model) {
        SystemOperLog operLog = operLogService.findById(operId);
        model.addAttribute("operLog", operLog);
        return page("info");
    }

    /* JSON API */

    @ApiOperation(value = "操作日志列表")
    @GetMapping("/list.json")
    @ResponseBody
    public Result<?> listForJson(@RequestParam Map params) {
        List<SystemOperLog> data = operLogService.findAll(params);
        PageInfo pageInfo = new PageInfo(data);
        return ResultHelper.ok(pageInfo);
    }

    @Override
    public String getModel() {
        return model;
    }

    @Override
    public String getSubModel() {
        return subModel;
    }
}
